package command.usuario;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import model.Caso;

import command.ICommand;

import dao.assinatura.CasoDAO;
import dao.fabrica.FabricaDAO;

public class DeletarCasoCommand implements ICommand {
	
	private String casoId;
	
	public String execute(HttpServletRequest request) throws ServletException, IOException {
		
		
		try {
			
			
			casoId = request.getParameter("c"); 
			if (casoId != null )
			{

				CasoDAO casoDAO = FabricaDAO.createCaso();
		
				Caso caso = casoDAO.getCasoById(Integer.parseInt(casoId));	
				
				if (caso != null){
					casoDAO.deleteCaso(Integer.parseInt(casoId));
				}
			 
			}else{
				 return "/paginas/inicio.jsp?resultado=FALSE";
				 
			 }
			 
			
			
		} catch (SQLException e) {
			e.printStackTrace();
			return "/paginas/cadastro/cadastro_invalido.jsp";
		}
	return "/paginas/inicio.jsp?resultado=OK";

}
}
